﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ConjureBivouac2012.Object
{
    public abstract class AbstractBullet : Entity
    {
        protected int timeLife = 5;
        protected int timer = 0;
        protected float _speed = 50;
        protected string contentName = "Bullet/Bullet";
        private int _size = -1;

        public bool Visible = false;
        
        public AbstractBullet(int size, float speed)
        {
            base.Initialize();
            _speed = speed;
            LoadContent(GameInfo.GetInstance().GetContent());

            if(size > 0)
            {
                _size = size;
                this.sprite.Scale = (float)_size/sprite.Source.Width;
            }
        }

        public abstract void Fire(Entity owner, Vector2 theDirection);

        public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager contentManager)
        {
            sprite.LoadContent(contentManager, contentName+1);
            sprite.Depth = 0.7f;
        }

        public override void destroyMe()
        {
            timeLife = 0;
        }

        public override void Update(GameTime time)
        {
            base.Update(time);

            if (_size > 0)
            {
                this.sprite.Scale = (float)_size / sprite.Source.Width;
            }

            if (time.TotalGameTime.Seconds - timer >= 1)
            {
                timer = time.TotalGameTime.Seconds;
                timeLife--;
                if (this.Velocity.X > _speed) this.Velocity.X = this.Velocity.X - 10;
                if (this.Velocity.Y > _speed) this.Velocity.Y = this.Velocity.Y - 10;
            }
        }

        public override bool hasToBeDestroyed()
        {
            return (timeLife <= 0);
        }
    }
}
